安裝 Python & pip
sudo apt install python3 python3-pip
sudo apt install python-is-python3
安裝 Ray
pip install ray[default]
$ pip show ray
Name: ray
Version: 2.7.0
Summary: Ray provides a simple, universal API for building distributed applications.
Home-page: https://github.com/ray-project/ray
Author: Ray Team
Author-email: ray-dev@googlegroups.com
License: Apache 2.0
Location: /home/jimmyliao/.local/lib/python3.10/site-packages
Requires: aiosignal, click, filelock, frozenlist, jsonschema, msgpack, numpy, packaging, protobuf, pyyaml, requests
Required-by:
建立 Ray head node
ray start --head
$ ray start --head
Enable usage stats collection? This prompt will auto-proceed in 10 seconds to avoid blocking cluster startup. Confirm [Y/n]: y
Usage stats collection is enabled. To disable this, add `--disable-usage-stats` to the command that starts the cluster, or run the following command: `ray disable-usage-stats` before starting the cluster. See https://docs.ray.io/en/master/cluster/usage-stats.html for more details.
Local node IP: 10.0.0.14
--------------------
Ray runtime started.
--------------------
Next steps
To add another node to this Ray cluster, run
ray start --address='10.0.0.14:6379'
建立測試程式
test.py
import ray
ray.init(address='auto')
@ray.remote
def f():
return 1
f.remote()
執行測試程式
python test.py
2023-10-05 15:31:34,673 INFO worker.py:1458 -- Connecting to existing Ray cluster at address: 10.0.0.14:6379...
2023-10-05 15:31:34,684 INFO worker.py:1633 -- Connected to Ray cluster. View the dashboard at 127.0.0.1:8265
查看結果
ray dashboard
停止 Ray head node
ray stop
Reference: